
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>RTSP · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-versions-select/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="RTP.html" />
    
    
    <link rel="prev" href="音视频基础.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    项目说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../linux/linux基础.html">
            
                <a href="../linux/linux基础.html">
            
                    
                    linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../linux/linux基础.html">
            
                <a href="../linux/linux基础.html">
            
                    
                    linux基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../linux/android底层开发.html">
            
                <a href="../linux/android底层开发.html">
            
                    
                    android底层开发
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../c语言/c基础.html">
            
                <a href="../c语言/c基础.html">
            
                    
                    c
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../c语言/c基础.html">
            
                <a href="../c语言/c基础.html">
            
                    
                    c基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../c++/c++基础.html">
            
                <a href="../c++/c++基础.html">
            
                    
                    c++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../c++/c++基础.html">
            
                <a href="../c++/c++基础.html">
            
                    
                    c++基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../QT/QT基础.html">
            
                <a href="../QT/QT基础.html">
            
                    
                    QT
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../QT/QT基础.html">
            
                <a href="../QT/QT基础.html">
            
                    
                    QT基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../jni/JNI基础.html">
            
                <a href="../jni/JNI基础.html">
            
                    
                    JNI
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../jni/JNI基础.html">
            
                <a href="../jni/JNI基础.html">
            
                    
                    JNI基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../jni/JNI例子.html">
            
                <a href="../jni/JNI例子.html">
            
                    
                    JNI例子
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../SDL/SDL基础.html">
            
                <a href="../SDL/SDL基础.html">
            
                    
                    SDL
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../SDL/SDL基础.html">
            
                <a href="../SDL/SDL基础.html">
            
                    
                    SDL基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../ffmpeg/ffmpeg基础.html">
            
                <a href="../ffmpeg/ffmpeg基础.html">
            
                    
                    ffmpeg
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../ffmpeg/ffmpeg基础.html">
            
                <a href="../ffmpeg/ffmpeg基础.html">
            
                    
                    ffmpeg基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../ffmpeg/ffmpeg示例代码.html">
            
                <a href="../ffmpeg/ffmpeg示例代码.html">
            
                    
                    ffmpeg示例代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../ffmpeg/ffmpeg软解rtsp简单直播.html">
            
                <a href="../ffmpeg/ffmpeg软解rtsp简单直播.html">
            
                    
                    ffmpeg软解rtsp简单直播
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../ffmpeg/rtsp服务器.html">
            
                <a href="../ffmpeg/rtsp服务器.html">
            
                    
                    rtsp服务器Windows
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../opencv/opencv模块.html">
            
                <a href="../opencv/opencv模块.html">
            
                    
                    opencv模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../opencv/opencv.html">
            
                <a href="../opencv/opencv.html">
            
                    
                    opencv
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../openSLES/openSLES基础.html">
            
                <a href="../openSLES/openSLES基础.html">
            
                    
                    openSLES
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../openSLES/openSLES基础.html">
            
                <a href="../openSLES/openSLES基础.html">
            
                    
                    openSLES基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../SoundTouch/移植SoundTouch.html">
            
                <a href="../SoundTouch/移植SoundTouch.html">
            
                    
                    SoundTouch
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../SoundTouch/移植SoundTouch.html">
            
                <a href="../SoundTouch/移植SoundTouch.html">
            
                    
                    移植SoundTouch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../SoundTouch/实现音频变速和变调.html">
            
                <a href="../SoundTouch/实现音频变速和变调.html">
            
                    
                    实现音频变速和变调
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../openGLES/openGLES基础.html">
            
                <a href="../openGLES/openGLES基础.html">
            
                    
                    openGLES模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../openGLES/openGLES基础.html">
            
                <a href="../openGLES/openGLES基础.html">
            
                    
                    openGLES基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../openGLES/GLSL基础.html">
            
                <a href="../openGLES/GLSL基础.html">
            
                    
                    GLSL基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../openGLES/openglES示例.html">
            
                <a href="../openGLES/openglES示例.html">
            
                    
                    openglES示例
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="音视频基础.html">
            
                <a href="音视频基础.html">
            
                    
                    音视频术语-文件格式-协议
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="音视频基础.html">
            
                <a href="音视频基础.html">
            
                    
                    音视频基础
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.13.2" data-path="RTSP.html">
            
                <a href="RTSP.html">
            
                    
                    RTSP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="RTP.html">
            
                <a href="RTP.html">
            
                    
                    RTP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="RTCP.html">
            
                <a href="RTCP.html">
            
                    
                    RTCP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="H264.html">
            
                <a href="H264.html">
            
                    
                    H264
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.6" data-path="YUV.html">
            
                <a href="YUV.html">
            
                    
                    YUV
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.7" data-path="SurfaceView.html">
            
                <a href="SurfaceView.html">
            
                    
                    SurfaceView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.8" data-path="RTMP.html">
            
                <a href="RTMP.html">
            
                    
                    RTMP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.9" data-path="AAC详解.html">
            
                <a href="AAC详解.html">
            
                    
                    AAC详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../音视频相关代码/音视频相关代码.html">
            
                <a href="../音视频相关代码/音视频相关代码.html">
            
                    
                    音视频相关代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../ndk/NDK编译基础.html">
            
                <a href="../ndk/NDK编译基础.html">
            
                    
                    NDK工程编译
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../ndk/NDK编译基础.html">
            
                <a href="../ndk/NDK编译基础.html">
            
                    
                    NDK编译基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../ndk/cmake方式.html">
            
                <a href="../ndk/cmake方式.html">
            
                    
                    cmake
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../ndk/Android.mk模板.html">
            
                <a href="../ndk/Android.mk模板.html">
            
                    
                    Android.mk
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../ndk/Application.mk模板.html">
            
                <a href="../ndk/Application.mk模板.html">
            
                    
                    Application.mk
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >RTSP</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#rtsp"><b>1. </b>rtsp</a></li><ul><li><span class="title-icon "></span><a href="#rtp&#x3001;rtsp&#x3001;rtcp&#x7684;&#x533A;&#x522B;"><b>1.1. </b>RTP&#x3001;RTSP&#x3001;RTCP&#x7684;&#x533A;&#x522B;</a></li><li><span class="title-icon "></span><a href="#rtsp-&#x7684;&#x4EA4;&#x4E92;&#x8FC7;&#x7A0B;-&#xFF08;&#x5BA2;&#x6237;&#x7AEF;&#x548C;&#x670D;&#x52A1;&#x7AEF;&#xFF09;"><b>1.2. </b>rtsp &#x7684;&#x4EA4;&#x4E92;&#x8FC7;&#x7A0B; &#xFF08;&#x5BA2;&#x6237;&#x7AEF;&#x548C;&#x670D;&#x52A1;&#x7AEF;&#xFF09;</a></li><li><span class="title-icon "></span><a href="#&#x642D;&#x5EFA;&#x3001;&#x6D4B;&#x8BD5;rtsp&#x4EA4;&#x4E92;"><b>1.3. </b>&#x642D;&#x5EFA;&#x3001;&#x6D4B;&#x8BD5;rtsp&#x4EA4;&#x4E92;</a></li><ul><li><span class="title-icon "></span><a href="#&#x91C7;&#x96C6;&#x3001;&#x63A8;&#x6D41;"><b>1.3.1. </b>&#x91C7;&#x96C6;&#x3001;&#x63A8;&#x6D41;</a></li><li><span class="title-icon "></span><a href="#&#x6D41;&#x5A92;&#x4F53;&#x670D;&#x52A1;&#x5668;"><b>1.3.2. </b>&#x6D41;&#x5A92;&#x4F53;&#x670D;&#x52A1;&#x5668;</a></li><li><span class="title-icon "></span><a href="#&#x89E3;&#x7801;&#x64AD;&#x653E;"><b>1.3.3. </b>&#x89E3;&#x7801;&#x64AD;&#x653E;</a></li></ul><li><span class="title-icon "></span><a href="#&#x89E3;rtsp&#x534F;&#x8BAE;&#x83B7;&#x5F97;h264-&#xFF0C;java&#x5B9E;&#x73B0;demo"><b>1.4. </b>&#x89E3;rtsp&#x534F;&#x8BAE;&#x83B7;&#x5F97;H264 &#xFF0C;java&#x5B9E;&#x73B0;demo</a></li><ul><li><span class="title-icon "></span><a href="#&#x4F7F;&#x7528;&#x65B9;&#x6CD5;"><b>1.4.1. </b>&#x4F7F;&#x7528;&#x65B9;&#x6CD5;</a></li></ul></ul></ul></div><a href="#rtsp" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="rtsp"><a name="rtsp" class="anchor-navigation-ex-anchor" href="#rtsp"><i class="fa fa-link" aria-hidden="true"></i></a>1. rtsp</h1>
<pre><code class="lang-html">RTSP&#x88AB;&#x7528;&#x4E8E;&#x5EFA;&#x7ACB;&#x7684;&#x63A7;&#x5236;&#x5A92;&#x4F53;&#x6D41;&#x7684;&#x4F20;&#x8F93; &#x3002;
Rtp&#x534F;&#x8BAE;&#x63D0;&#x4F9B;&#x4E86;&#x65F6;&#x95F4;&#x6233;&#x548C;&#x5E8F;&#x5217;&#x53F7;&#x3002;&#x53D1;&#x9001;&#x7AEF;&#x5728;&#x91C7;&#x6837;&#x65F6;&#x8BBE;&#x7F6E;&#x65F6;&#x95F4;&#x6233;&#xFF0C;&#x63A5;&#x6536;&#x7AEF;&#x6536;&#x5230;&#x540E;&#xFF0C;&#x4F1A;&#x6309;&#x7167;&#x65F6;&#x95F4;&#x6233;&#x4F9D;&#x6B21;&#x64AD;&#x653E;&#x3002;

RTP&#x672C;&#x8EAB;&#x53EA;&#x4FDD;&#x8BC1;&#x5B9E;&#x65F6;&#x6570;&#x636E;&#x7684;&#x4F20;&#x8F93;&#xFF0C;&#x5E76;&#x4E0D;&#x80FD;&#x4E3A;&#x6309;&#x987A;&#x5E8F;&#x4F20;&#x9001;&#x7684;&#x6570;&#x636E;&#x5305;&#x63D0;&#x4F9B;&#x53EF;&#x9760;&#x7684;&#x4F20;&#x9001;&#x673A;&#x5236;&#xFF0C;&#x4E5F;&#x4E0D;&#x63D0;&#x4F9B;&#x6D41;&#x91CF;&#x548C;&#x62E5;&#x585E;&#x63A7;&#x5236;&#xFF0C;
&#x5B83;&#x4F9D;&#x9760;RTCP&#x6765;&#x63D0;&#x4F9B;&#x8FD9;&#x4E9B;&#x670D;&#x52A1;&#x3002;

RTCP&#x901A;&#x5E38;&#x4E0E;RTP&#x914D;&#x5408;&#x4F7F;&#x7528;&#xFF0C;&#x7528;&#x4EE5;&#x7BA1;&#x7406;&#x4F20;&#x8F93;&#x8D28;&#x91CF;&#x5728;&#x5F53;&#x524D;&#x8FDB;&#x7A0B;&#x4E4B;&#x95F4;&#x7684;&#x4EA4;&#x6362;&#x4FE1;&#x606F;&#x3002;
&#x5728;RTP&#x4F1A;&#x8BDD;&#x671F;&#x95F4;&#xFF0C;&#x5404;&#x53C2;&#x4E0E;&#x8005;&#x5468;&#x671F;&#x6027;&#x7684;&#x4F20;&#x9001;RTCP&#x5305;&#xFF0C;RTCP&#x5305;&#x4E2D;&#x5305;&#x542B;&#x5DF2;&#x53D1;&#x9001;&#x6570;&#x636E;&#x5305;&#x7684;&#x6570;&#x91CF;&#x3001;&#x4E22;&#x5931;&#x7684;&#x6570;&#x636E;&#x5305;&#x7684;&#x6570;&#x91CF;&#x7B49;&#x7EDF;&#x8BA1;&#x8D44;&#x6599;&#x3002;
&#x670D;&#x52A1;&#x5668;&#x53EF;&#x4EE5;&#x5229;&#x7528;&#x8FD9;&#x4E9B;&#x4FE1;&#x606F;&#x52A8;&#x6001;&#x7684;&#x6539;&#x53D8;&#x4F20;&#x8F93;&#x901F;&#x7387;&#xFF0C;&#x751A;&#x81F3;&#x6539;&#x53D8;&#x6709;&#x6548;&#x8F7D;&#x8377;&#x7684;&#x7C7B;&#x578B;&#x3002;
RTSP&#x901A;&#x5E38;&#x4F7F;&#x7528;RTP&#x534F;&#x8BAE;&#x6765;&#x4F20;&#x9001;&#x5B9E;&#x65F6;&#x6D41;&#xFF0C;RTP&#x4E00;&#x822C;&#x4F7F;&#x7528;&#x5076;&#x6570;&#x7AEF;&#x53E3;&#xFF0C;&#x800C;RTCP&#x4F7F;&#x7528;&#x76F8;&#x90BB;&#x7684;&#x5947;&#x6570;&#x7AEF;&#x53E3;&#xFF0C;&#x5373;RTP&#x7AEF;&#x53E3;&#x53F7;+1&#x3002;

&#x6CE8;&#x610F;: RTP &#x672C;&#x8EAB;&#x6CA1;&#x6709;&#x63D0;&#x4F9B;&#x4EFB;&#x4F55;&#x7684;&#x673A;&#x5236;&#x6765;&#x786E;&#x4FDD;&#x5B9E;&#x65F6;&#x7684;&#x4F20;&#x8F93;&#x6216;&#x5176;&#x4ED6;&#x7684;&#x670D;&#x52A1;&#x8D28;&#x91CF;&#x4FDD;&#x8BC1;&#xFF0C;&#x800C;&#x662F;&#x7531;&#x5E95;&#x5C42;&#x7684;&#x670D;&#x52A1;&#x6765;&#x5B8C;&#x6210;&#x3002;
&#x5B83;&#x4E0D;&#x4FDD;&#x8BC1;&#x4F20;&#x8F93;&#x6216;&#x9632;&#x6B62;&#x4E71;&#x5E8F;&#x4F20;&#x8F93;,&#x5B83;&#x4E0D;&#x5047;&#x5B9A;&#x4E0B;&#x5C42;&#x7F51;&#x7EDC;&#x662F;&#x5426;&#x53EF;&#x9760;,&#x662F;&#x5426;&#x6309;&#x987A;&#x5E8F;&#x4F20;&#x9001;&#x6570;&#x636E;&#x5305;&#x3002;
</code></pre>
<h2 id="rtp&#x3001;rtsp&#x3001;rtcp&#x7684;&#x533A;&#x522B;"><a name="rtp&#x3001;rtsp&#x3001;rtcp&#x7684;&#x533A;&#x522B;" class="anchor-navigation-ex-anchor" href="#rtp&#x3001;rtsp&#x3001;rtcp&#x7684;&#x533A;&#x522B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. RTP&#x3001;RTSP&#x3001;RTCP&#x7684;&#x533A;&#x522B;</h2>
<pre><code class="lang-xml">Rtsp
&#x8FDB;&#x884C;&#x670D;&#x52A1;&#x7AEF;&#x548C;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x4FE1;&#x606F;&#x4EA4;&#x6D41;&#x3002;
&#x4F8B;&#x5982;&#x5BA2;&#x6237;&#x7AEF;&#x8BE2;&#x95EE;&#x670D;&#x52A1;&#x5668;&#x652F;&#x6301;&#x54EA;&#x4E9B;&#x65B9;&#x6CD5;&#x3001;&#x534F;&#x8BAE;&#x3001;sps&#x3001;pps&#x7B49;&#x3002;&#x6C9F;&#x901A;&#x4EE5;&#x4EC0;&#x4E48;&#x65B9;&#x5F0F;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#xFF0C;&#x662F;&#x5426;&#x8981;&#x5F00;&#x59CB;&#x53D1;&#x9001;&#x6570;&#x636E;&#x4E86;&#x7B49;&#x3002;

Rtp
&#x670D;&#x52A1;&#x5668;&#x4EE5;&#x7EA6;&#x5B9A;&#x597D;&#x7684;&#x683C;&#x5F0F;&#x5F80;&#x5BA2;&#x6237;&#x7AEF;&#x8FDB;&#x884C;&#x53D1;&#x9001;&#x5C01;&#x88C5;&#x597D;&#x7684;&#x6570;&#x636E;&#x3002;

RTCP
&#x5F53;&#x5BA2;&#x6237;&#x7AEF;&#x53D1;&#x73B0;RTP&#x4E22;&#x5305;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7EA6;&#x5B9A;&#x597D;&#x7684;&#x683C;&#x5F0F;&#x5F80;&#x670D;&#x52A1;&#x5668;&#x53D1;&#x9001;&#x6570;&#x636E;&#xFF0C;&#x8981;&#x6C42;&#x670D;&#x52A1;&#x5668;&#x91CD;&#x53D1;&#x6570;&#x636E;&#x3002;
&#x6CE8;&#xFF1A;&#x867D;&#x7136;UDP&#x662F;&#x5355;&#x5411;&#x901A;&#x4FE1;&#x7684;&#xFF0C; &#x4F46;&#x662F; RTP + RTCP &#x5176;&#x5B9E;&#x76F8;&#x5F53;&#x4E8E;&#x5EFA;&#x7ACB;&#x8D77;&#x4E86;&#x4E00;&#x4E2A;&#x53CC;&#x5411;&#x5BF9;&#x8BDD;&#x7684;&#x673A;&#x5236;&#x4E86;&#x3002;
</code></pre>
<h2 id="rtsp-&#x7684;&#x4EA4;&#x4E92;&#x8FC7;&#x7A0B;-&#xFF08;&#x5BA2;&#x6237;&#x7AEF;&#x548C;&#x670D;&#x52A1;&#x7AEF;&#xFF09;"><a name="rtsp-&#x7684;&#x4EA4;&#x4E92;&#x8FC7;&#x7A0B;-&#xFF08;&#x5BA2;&#x6237;&#x7AEF;&#x548C;&#x670D;&#x52A1;&#x7AEF;&#xFF09;" class="anchor-navigation-ex-anchor" href="#rtsp-&#x7684;&#x4EA4;&#x4E92;&#x8FC7;&#x7A0B;-&#xFF08;&#x5BA2;&#x6237;&#x7AEF;&#x548C;&#x670D;&#x52A1;&#x7AEF;&#xFF09;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. rtsp &#x7684;&#x4EA4;&#x4E92;&#x8FC7;&#x7A0B; &#xFF08;&#x5BA2;&#x6237;&#x7AEF;&#x548C;&#x670D;&#x52A1;&#x7AEF;&#xFF09;</h2>
<pre><code class="lang-xml">1&#x3001;OPTIONS&#xFF08;&#x53EF;&#x9009;&#xFF09;
RTSP&#x5BA2;&#x6237;&#x7AEF;   &#x2014;&gt; RTSP&#x670D;&#x52A1;&#x5668;&#x7AEF;  OPTIONS&#x547D;&#x4EE4;      //&#x8BE2;&#x95EE;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x6709;&#x54EA;&#x4E9B;&#x65B9;&#x6CD5;&#x53EF;&#x4F7F;&#x7528;
RTSP&#x670D;&#x52A1;&#x5668;&#x7AEF; &#x2014;&gt; RTSP&#x5BA2;&#x6237;&#x7AEF;  &#x56DE;&#x590D;OPTIONS&#x547D;&#x4EE4;    //&#x56DE;&#x590D;&#x5BA2;&#x6237;&#x7AEF;&#x670D;&#x52A1;&#x5668;&#x652F;&#x6301;&#x7684;&#x65B9;&#x6CD5;  

2&#x3001;DESCRIBE &#xFF08;&#x53EF;&#x9009;&#xFF09;
RTSP&#x5BA2;&#x6237;&#x7AEF;   &#x2014;&gt;  RTSP&#x670D;&#x52A1;&#x5668;&#x7AEF;   DESCRIBE&#x547D;&#x4EE4;      //&#x8BF7;&#x6C42;&#x5BF9;&#x5A92;&#x4F53;&#x8D44;&#x6E90;&#x7684;&#x63CF;&#x8FF0;&#x4FE1;&#x606F;
RTSP&#x670D;&#x52A1;&#x5668;&#x7AEF; &#x2014;&gt;  RTSP&#x5BA2;&#x6237;&#x7AEF; &#x3000;&#x3000;&#x56DE;&#x590D;DESCRIBE&#x547D;&#x4EE4;&#x3000;//&#x56DE;&#x590D;&#x5BA2;&#x6237;&#x7AEF;&#x67D0;&#x4E2A;&#x5A92;&#x4F53;&#x8D44;&#x6E90;&#x7684;&#x63CF;&#x8FF0;&#x4FE1;&#x606F;&#xFF08;&#x5373;SDP&#xFF09;

3&#x3001;SETUP&#xFF08;&#x5FC5;&#x9009;&#xFF09;
RTSP&#x5BA2;&#x6237;&#x7AEF;   &#x2014;&gt; RTSP&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x3000;SETUP&#x547D;&#x4EE4;       //&#x8BF7;&#x6C42;&#x5EFA;&#x7ACB;&#x5BF9;&#x67D0;&#x4E2A;&#x5A92;&#x4F53;&#x8D44;&#x6E90;&#x7684;&#x8FDE;&#x63A5;
RTSP&#x670D;&#x52A1;&#x5668;&#x7AEF; &#x2014;&gt;  RTSP&#x5BA2;&#x6237;&#x7AEF;&#x3000; &#x56DE;&#x590D;SETUP&#x547D;&#x4EE4;&#x3000; //&#x56DE;&#x590D;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x7684;&#x7ED3;&#x679C;
&#x3000;&#x3000;
4&#x3001;PLAY&#xFF08;&#x5FC5;&#x9009;&#xFF09;
RTSP&#x5BA2;&#x6237;&#x7AEF;    &#x2014;&gt;  RTSP&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x3000; PLAY&#x547D;&#x4EE4;&#x3000;&#x3000;&#x3000;   //&#x8BF7;&#x6C42;&#x64AD;&#x653E;&#x5A92;&#x4F53;&#x8D44;&#x6E90;
RTSP&#x670D;&#x52A1;&#x5668;&#x7AEF;  &#x2014;&gt;  RTSP&#x5BA2;&#x6237;&#x7AEF;&#x3000;&#x3000; &#x56DE;&#x590D;PLAY&#x547D;&#x4EE4;&#x3000;&#x3000; //&#x56DE;&#x590D;&#x64AD;&#x653E;&#x7684;&#x7ED3;&#x679C;

5&#x3001;&#x5176;&#x4ED6;&#x7684;&#x4EA4;&#x4E92;&#x65B9;&#x6CD5;&#xFF0C;&#x8BF7;&#x81EA;&#x884C;&#x67E5;&#x9605; &#x3002;
&#x4F8B;&#x5982; TEARDOWN&#x3001;PAUSE&#x3001;SCALE&#x3001; GET_PARAMETER&#x3001;SET_PARAMETER
</code></pre>
<h2 id="&#x642D;&#x5EFA;&#x3001;&#x6D4B;&#x8BD5;rtsp&#x4EA4;&#x4E92;"><a name="&#x642D;&#x5EFA;&#x3001;&#x6D4B;&#x8BD5;rtsp&#x4EA4;&#x4E92;" class="anchor-navigation-ex-anchor" href="#&#x642D;&#x5EFA;&#x3001;&#x6D4B;&#x8BD5;rtsp&#x4EA4;&#x4E92;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. &#x642D;&#x5EFA;&#x3001;&#x6D4B;&#x8BD5;rtsp&#x4EA4;&#x4E92;</h2>
<p>&#x53EF;&#x4EE5;&#x91C7;&#x7528;&#x4EE5;&#x4E0B;&#x65B9;&#x6848;&#x642D;&#x5EFA;&#x4E00;&#x5957;&#x7CFB;&#x7EDF;&#x3002;</p>
<h3 id="&#x91C7;&#x96C6;&#x3001;&#x63A8;&#x6D41;"><a name="&#x91C7;&#x96C6;&#x3001;&#x63A8;&#x6D41;" class="anchor-navigation-ex-anchor" href="#&#x91C7;&#x96C6;&#x3001;&#x63A8;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.1. &#x91C7;&#x96C6;&#x3001;&#x63A8;&#x6D41;</h3>
<p>&#x7528;<a href="https://github.com/EasyDSS/EasyPusher-Android" target="_blank">EasyPusher</a> , &#x5546;&#x4E1A;&#x9700;&#x8981;&#x6388;&#x6743;&#x3002;</p>
<h3 id="&#x6D41;&#x5A92;&#x4F53;&#x670D;&#x52A1;&#x5668;"><a name="&#x6D41;&#x5A92;&#x4F53;&#x670D;&#x52A1;&#x5668;" class="anchor-navigation-ex-anchor" href="#&#x6D41;&#x5A92;&#x4F53;&#x670D;&#x52A1;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2. &#x6D41;&#x5A92;&#x4F53;&#x670D;&#x52A1;&#x5668;</h3>
<p>&#x7528;<a href="https://github.com/EasyDarwin/EasyDarwin/tree/master/EasyDarwin" target="_blank">EasyDarwin </a> &#xFF0C; &#x5B8C;&#x5168;&#x514D;&#x8D39;&#x3002;</p>
<h3 id="&#x89E3;&#x7801;&#x64AD;&#x653E;"><a name="&#x89E3;&#x7801;&#x64AD;&#x653E;" class="anchor-navigation-ex-anchor" href="#&#x89E3;&#x7801;&#x64AD;&#x653E;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.3. &#x89E3;&#x7801;&#x64AD;&#x653E;</h3>
<p>&#x7528; VLC &#xFF0C;&#x5B8C;&#x5168;&#x514D;&#x8D39;&#x3002;</p>
<h2 id="&#x89E3;rtsp&#x534F;&#x8BAE;&#x83B7;&#x5F97;h264-&#xFF0C;java&#x5B9E;&#x73B0;demo"><a name="&#x89E3;rtsp&#x534F;&#x8BAE;&#x83B7;&#x5F97;h264-&#xFF0C;java&#x5B9E;&#x73B0;demo" class="anchor-navigation-ex-anchor" href="#&#x89E3;rtsp&#x534F;&#x8BAE;&#x83B7;&#x5F97;h264-&#xFF0C;java&#x5B9E;&#x73B0;demo"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. &#x89E3;rtsp&#x534F;&#x8BAE;&#x83B7;&#x5F97;H264 &#xFF0C;java&#x5B9E;&#x73B0;demo</h2>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RtspClient</span></span>{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> String TAG=<span class="hljs-string">&quot;RtspClient&quot;</span> ;
    <span class="hljs-comment">/**&#x662F;&#x5426;&#x662F;tcp&#x65B9;&#x5F0F;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">boolean</span> isTCPtranslate;
    <span class="hljs-keyword">private</span> String hostIp;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> port;
    <span class="hljs-keyword">private</span> String rtspUrl ;
    <span class="hljs-comment">/**rtsp&#x7248;&#x672C;&#x53F7;&#xFF0C;&#x5FC5;&#x987B;&#x662F;1.0? &#x8FD8;&#x4E0D;&#x786E;&#x5B9A;&#xFF01;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String VERSION = <span class="hljs-string">&quot; RTSP1.0\r\n&quot;</span>;
    <span class="hljs-comment">/**rtsp&#x670D;&#x52A1;&#x5668;&#x6B63;&#x786E;&#x53CD;&#x5E94;&#x6807;&#x8BB0;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String RTSP_OK = <span class="hljs-string">&quot;RTSP/1.0 200 OK&quot;</span>;
    <span class="hljs-comment">/**&#x8BF7;&#x6C42;&#x56DE;&#x5E94;&#x5BF9;&#x7684;&#x5E8F;&#x5217;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> seq=<span class="hljs-number">1</span>;
    <span class="hljs-comment">/**&#x4F1A;&#x8BDD; Session&#x5728;setup&#x8BF7;&#x6C42;&#x540E;&#x8FD4;&#x56DE;  */</span>
    <span class="hljs-keyword">private</span> String sessionid=<span class="hljs-keyword">null</span>;
    <span class="hljs-comment">/**trackID &#x5728; &#x8BF7;&#x6C42;Descrbe &#x4E4B;&#x540E;&#x8FD4;&#x56DE;*/</span>
    <span class="hljs-keyword">private</span> String trackInfo;
    <span class="hljs-comment">/**&#x8F6C;&#x6362;&#x8D26;&#x53F7;&#x548C;&#x5BC6;&#x7801;*/</span>
    <span class="hljs-keyword">private</span> String authorBase64;
    <span class="hljs-comment">/**&#x5BA2;&#x6237;&#x7AEF;&#x4EE3;&#x7406;&#x540D;&#x79F0;&#x968F;&#x610F;&#x586B;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> String UserAgent = <span class="hljs-string">&quot;RtspWalkera/1.0&quot;</span>;
    <span class="hljs-keyword">private</span> Socket mSocket;
    <span class="hljs-keyword">private</span> BufferedReader mBufferreader;
    <span class="hljs-keyword">private</span> OutputStream mOutputStream;
    <span class="hljs-comment">/**
     * &#x6784;&#x9020;&#x51FD;&#x6570; &#xFF0C; &#x8FDB;&#x884C;&#x53C2;&#x6570;&#x521D;&#x59CB;&#x5316;
     * <span class="hljs-doctag">@param</span> isTCPtranslate tcp&#x65B9;&#x5F0F;&#x8FD8;&#x662F; udp&#x65B9;&#x5F0F;
     * <span class="hljs-doctag">@param</span> hostIp  &#x670D;&#x52A1;&#x5668;ip
     * <span class="hljs-doctag">@param</span> port  &#x670D;&#x52A1;&#x5668;&#x7AEF;&#x53E3;
     * <span class="hljs-doctag">@param</span> rtspUrl  rtsp&#x64AD;&#x653E;&#x5730;&#x5740;
     * <span class="hljs-doctag">@param</span> authorName &#x767B;&#x5F55;&#x8D26;&#x53F7;
     * <span class="hljs-doctag">@param</span> authorPassword &#x767B;&#x5F55;&#x5BC6;&#x7801;
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">RtspClient</span><span class="hljs-params">(<span class="hljs-keyword">boolean</span> isTCPtranslate, String hostIp,<span class="hljs-keyword">int</span> port,
    String rtspUrl ,String authorName,String authorPassword)</span>  </span>{
        <span class="hljs-keyword">this</span>.isTCPtranslate = isTCPtranslate;
        <span class="hljs-keyword">this</span>.rtspUrl = rtspUrl;
        <span class="hljs-keyword">this</span>.hostIp = hostIp ;
        <span class="hljs-keyword">this</span>.port = port;
        <span class="hljs-keyword">if</span>(authorName == <span class="hljs-keyword">null</span> &amp;&amp; authorPassword == <span class="hljs-keyword">null</span>) {
            authorBase64 = <span class="hljs-keyword">null</span>;
        }  <span class="hljs-keyword">else</span> {
            <span class="hljs-comment">// &#x8FD4;&#x56DE;Base64&#x7F16;&#x7801;&#x8FC7;&#x7684;&#x5B57;&#x8282;&#x6570;&#x7EC4;&#x5B57;&#x7B26;&#x4E32;</span>
            authorBase64 = Base64.encodeToString((authorName+<span class="hljs-string">&quot;:&quot;</span>+authorPassword).getBytes(),Base64.DEFAULT);
        }
    }

    <span class="hljs-function"><span class="hljs-keyword">private</span> String <span class="hljs-title">addHeaders</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;CSeq: &quot;</span> + (seq++) + <span class="hljs-string">&quot;\r\n&quot;</span>
                + ((authorBase64 == <span class="hljs-keyword">null</span>)?<span class="hljs-string">&quot;&quot;</span>:(<span class="hljs-string">&quot;Authorization: Basic &quot;</span> +authorBase64 +<span class="hljs-string">&quot;\r\n&quot;</span>))
                + <span class="hljs-string">&quot;User-Agent: &quot;</span> + UserAgent + <span class="hljs-string">&quot;\r\n&quot;</span>
                + ((sessionid == <span class="hljs-keyword">null</span>)?<span class="hljs-string">&quot;&quot;</span>:(<span class="hljs-string">&quot;Session: &quot;</span> + sessionid + <span class="hljs-string">&quot;\r\n&quot;</span>))
                + <span class="hljs-string">&quot;\r\n&quot;</span>;
    }

    <span class="hljs-comment">/**
     * option&#x8BF7;&#x6C42; &lt;br&gt;
     *     &#x6B64;&#x6B65;&#x9AA4;&#x975E;&#x5FC5;&#x987B;
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doOption</span><span class="hljs-params">()</span></span>{
        StringBuilder sb = <span class="hljs-keyword">new</span> StringBuilder();
        sb.append(<span class="hljs-string">&quot;OPTIONS &quot;</span>);
        sb.append(<span class="hljs-keyword">this</span>.rtspUrl.substring(<span class="hljs-number">0</span>, rtspUrl.lastIndexOf(<span class="hljs-string">&quot;/&quot;</span>)));
        sb.append(VERSION);
        sb.append(addHeaders());
        <span class="hljs-keyword">try</span>{
            outQueue.put(sb.toString());
        }<span class="hljs-keyword">catch</span> (Exception e)  {}
    }

    <span class="hljs-comment">/**
     *  Describe &#x8BF7;&#x6C42;&lt;br&gt;
     *  sps &#x548C; pps &#x4F1A;&#x5728;&#x8FD9;&#x4E2A;&#x9636;&#x6BB5;&#x8FD4;&#x56DE;
     *  sprop-parameter-sets= Z0IAKpY1QMgEvTcBAQEC,aM48gA==
     *  &#x5C06;  sprop-parameter-sets &#x5BF9;&#x5E94;&#x7684;&#x503C;&#x7528;base64 &#x89E3;&#x7801;&#x5373;&#x53EF; 67 &#x548C;68
     *  &#x5206;&#x522B;&#x5BF9;&#x5E94;sps &#x548C;pps . &lt;br&gt;
     *      &#x4E0D;&#x8FC7;&#x6709;&#x7684;rtsp&#x670D;&#x52A1;&#x5668;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x6309;&#x6807;&#x51C6;&#x5199;&#x7684;&#x8BDD; &#xFF0C;sprop-parameter-sets &#x8FD4;&#x56DE;&#x7684;&#x503C;&#x53EF;&#x80FD;&#x4E3A;&#x7A7A;&#x3002;
     *      &#x6B64;&#x65F6; &#x5982;&#x679C;&#x60F3;&#x83B7;&#x53D6;sps &#x548C;pps &#x53EA;&#x80FD;&#x901A;&#x8FC7;rtsp&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE;&#x7684; &#x5E27;&#x6570;&#x636E;&#x4E2D;&#x53BB;&#x83B7;&#x53D6;&#x4E86;&#x3002;
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doDescribe</span><span class="hljs-params">()</span>  </span>{
        StringBuilder sb = <span class="hljs-keyword">new</span> StringBuilder();
        sb.append(<span class="hljs-string">&quot;DESCRIBE &quot;</span>);
        sb.append(<span class="hljs-keyword">this</span>.rtspUrl);
        sb.append(VERSION);
        sb.append(addHeaders());
        <span class="hljs-keyword">try</span>  {
            outQueue.put(sb.toString());
        }<span class="hljs-keyword">catch</span> (Exception e)  {}
    }

    <span class="hljs-comment">/**
     * &#x8BF7;&#x6C42;setup &#x3002; &lt;br&gt;
     * RTP/AVP/TCP : RTP&#x91C7;&#x7528;TCP&#x65B9;&#x5F0F; &lt;br&gt;
     * unicast&#x8868;&#x793A;&#x5355;&#x64AD;&lt;br&gt;
     * client_port=55640-55641 &#xFF1A;&#x524D;&#x4E00;&#x4E2A;&#x662F;RTP&#x7AEF;&#x53E3; &#xFF0C;&#x540E;&#x4E00;&#x4E2A;&#x662F;RTCP&#x7AEF;&#x53E3;&lt;br&gt;
     *
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doSetup</span><span class="hljs-params">( )</span>  </span>{
        StringBuilder sb = <span class="hljs-keyword">new</span> StringBuilder();
        <span class="hljs-keyword">if</span> ( isTCPtranslate ) {
            sb.append(<span class="hljs-string">&quot;SETUP &quot;</span>);
            sb.append(<span class="hljs-keyword">this</span>.rtspUrl);
            sb.append(<span class="hljs-string">&quot;/&quot;</span>);
            sb.append(trackInfo);
            sb.append(VERSION);
            sb.append(<span class="hljs-string">&quot;Transport: RTP/AVP/TCP;unicast;client_port=55640-55641&quot;</span> + <span class="hljs-string">&quot;\r\n&quot;</span>);
            sb.append(addHeaders());
        } <span class="hljs-keyword">else</span> {
            sb.append(<span class="hljs-string">&quot;SETUP &quot;</span>);
            sb.append(<span class="hljs-keyword">this</span>.rtspUrl);
            sb.append(<span class="hljs-string">&quot;/&quot;</span>);
            sb.append(trackInfo);
            sb.append(VERSION);
            sb.append(<span class="hljs-string">&quot;Transport: RTP/AVP/UDP;unicast;client_port=55640-55641&quot;</span> + <span class="hljs-string">&quot;\r\n&quot;</span>);
            sb.append(addHeaders());
        }
        <span class="hljs-keyword">try</span>  {
            outQueue.put(sb.toString());
        }<span class="hljs-keyword">catch</span> (Exception e)  {  }
    }

    <span class="hljs-comment">/**
     * play &#x8BF7;&#x6C42;
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doPlay</span><span class="hljs-params">()</span></span>{
        StringBuilder sb = <span class="hljs-keyword">new</span> StringBuilder();
        sb.append(<span class="hljs-string">&quot;PLAY &quot;</span>);
        sb.append(<span class="hljs-keyword">this</span>.rtspUrl);
        sb.append(VERSION);
        <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x64AD;&#x653E;&#x7684;&#x65F6;&#x95F4;&#x8303;&#x56F4;</span>
        sb.append(<span class="hljs-string">&quot;Range: npt=0.000-\r\n&quot;</span>);
        sb.append(addHeaders()) ;
        <span class="hljs-keyword">try</span>  {
            outQueue.put(sb.toString());
        }<span class="hljs-keyword">catch</span> (Exception e)  {  }
    }

    <span class="hljs-comment">/**
     * Pause &#x6682;&#x505C;&#x8BF7;&#x6C42;
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doPause</span><span class="hljs-params">()</span> </span>{
        StringBuilder sb = <span class="hljs-keyword">new</span> StringBuilder();
        sb.append(<span class="hljs-string">&quot;PAUSE &quot;</span>);
        sb.append(<span class="hljs-keyword">this</span>.rtspUrl);
        sb.append(<span class="hljs-string">&quot;/&quot;</span>);
        sb.append(VERSION);
        sb.append(addHeaders()) ;
        <span class="hljs-keyword">try</span>{
            outQueue.put(sb.toString());
        }<span class="hljs-keyword">catch</span> (Exception e)  {  }
    }

    <span class="hljs-comment">/**
     * &#x5173;&#x95ED;&#x8FDE;&#x63A5;
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doTeardown</span><span class="hljs-params">()</span></span>{
        StringBuilder sb = <span class="hljs-keyword">new</span> StringBuilder();
        sb.append(<span class="hljs-string">&quot;TEARDOWN &quot;</span>);
        sb.append(<span class="hljs-keyword">this</span>.rtspUrl);
        sb.append(<span class="hljs-string">&quot;/&quot;</span>);
        sb.append(VERSION);
        sb.append(addHeaders()) ;
        <span class="hljs-keyword">try</span>  {
            outQueue.put(sb.toString());
        }<span class="hljs-keyword">catch</span> (Exception e){ }
    }

    <span class="hljs-comment">/**
     * &#x5F80;&#x670D;&#x52A1;&#x5668;&#x53D1;&#x9001;&#x6570;&#x636E;
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">sendBytes</span><span class="hljs-params">(String questStr)</span>  </span>{
        <span class="hljs-keyword">try</span>  {
            <span class="hljs-keyword">byte</span>[] buffer= questStr.getBytes(<span class="hljs-string">&quot;UTF-8&quot;</span>);
            mOutputStream.write(buffer);
            mOutputStream.flush();
            Log.i(TAG ,<span class="hljs-string">&quot;&#x8BF7;&#x6C42;&#x670D;&#x52A1;&#x5668;&#xFF1A;&quot;</span>+questStr +<span class="hljs-string">&quot; &quot;</span>+outQueue.size());
        }<span class="hljs-keyword">catch</span> (Exception e)
        {
            Log.i(TAG ,<span class="hljs-string">&quot;&#x8BF7;&#x6C42;&#x670D;&#x52A1;&#x5668;&#x5F02;&#x5E38;&#xFF1A;&quot;</span>+e.getMessage());
        }
    }

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">boolean</span> isStopReceive =<span class="hljs-keyword">false</span> ;
    <span class="hljs-comment">/***
     * rtsp &#x63A5;&#x6536;&#x5B50;&#x7EBF;&#x7A0B;
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ReceiveThread</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Thread</span></span>{
        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span>  </span>{
            <span class="hljs-keyword">while</span>(!isStopReceive)  {
                <span class="hljs-keyword">try</span>  {
                    <span class="hljs-keyword">if</span>(mBufferreader!=<span class="hljs-keyword">null</span>)
                    {
                        String line  ;
                        <span class="hljs-keyword">if</span>( (line = mBufferreader.readLine()) != <span class="hljs-keyword">null</span>)
                        {
                            Log.i(TAG ,<span class="hljs-string">&quot;&#x6536;&#x5230;&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE;=&quot;</span> + line);
                        }<span class="hljs-keyword">else</span> {
                            Log.i(TAG ,<span class="hljs-string">&quot;&#x6536;&#x5230;&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE; line==null&quot;</span> );
                        }
                    }
                    <span class="hljs-comment">//&#x4F11;&#x7720;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;</span>
                    Thread.sleep(<span class="hljs-number">60</span>);
                }<span class="hljs-keyword">catch</span> (Exception e)
                {
                    Log.i(TAG ,<span class="hljs-string">&quot;&#x63A5;&#x6536;&#x670D;&#x52A1;&#x5668;&#x5F02;&#x5E38;&quot;</span> +e.getLocalizedMessage());
                }
            }
        }
    }

    <span class="hljs-keyword">private</span> LinkedBlockingDeque&lt;<span class="hljs-keyword">byte</span>[]&gt; rtpDataBuffer = <span class="hljs-keyword">new</span> LinkedBlockingDeque&lt;&gt;();
    <span class="hljs-keyword">private</span> DatagramSocket mUdpSocket;
    <span class="hljs-keyword">private</span> DatagramPacket mUdpPackets;
    <span class="hljs-keyword">int</span> udpPort = <span class="hljs-number">55640</span>; <span class="hljs-comment">//55640- 55641</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">byte</span>[] message = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[<span class="hljs-number">2048</span>];
    <span class="hljs-comment">/***
     * upd rtp &#x63A5;&#x6536;&#x5B50;&#x7EBF;&#x7A0B;
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ReceiveRTPUdpThread</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Thread</span>  </span>{
        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span></span>{
            <span class="hljs-keyword">while</span>(!isStopReceive)  {
                <span class="hljs-keyword">try</span>  {
                    <span class="hljs-keyword">if</span>(mUdpSocket==<span class="hljs-keyword">null</span>)
                    {
                        mUdpSocket = <span class="hljs-keyword">new</span> DatagramSocket(udpPort);
                        mUdpPackets = <span class="hljs-keyword">new</span> DatagramPacket(message,message.length);
                    }<span class="hljs-keyword">else</span>{
                        mUdpSocket.receive(mUdpPackets);
                        <span class="hljs-keyword">byte</span>[] buffer = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[mUdpPackets.getLength()];
                        System.arraycopy(mUdpPackets.getData(), <span class="hljs-number">0</span>, buffer, <span class="hljs-number">0</span>, mUdpPackets.getLength());
                        <span class="hljs-keyword">try</span> {
                            rtpDataBuffer.put(buffer);
                        } <span class="hljs-keyword">catch</span> (InterruptedException e) {
                            Log.e(TAG,<span class="hljs-string">&quot;The buffer queue is full , wait for the place..&quot;</span>);
                        }
                    }

                    <span class="hljs-comment">//&#x4F11;&#x7720;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;</span>
                    Thread.sleep(<span class="hljs-number">0</span>);
                }<span class="hljs-keyword">catch</span> (Exception e)
                {
                    Log.i(TAG ,<span class="hljs-string">&quot;udp&#x63A5;&#x6536;&#x670D;&#x52A1;&#x5668;&#x5F02;&#x5E38;&quot;</span> +e.getLocalizedMessage());
                }
            }
        }
    }

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">byte</span>[]getRtpData(){
        <span class="hljs-keyword">byte</span>[] nalu =<span class="hljs-keyword">null</span>;
        <span class="hljs-keyword">if</span>(rtpDataBuffer !=<span class="hljs-keyword">null</span> &amp;&amp; rtpDataBuffer.size()&gt;<span class="hljs-number">0</span>){
            <span class="hljs-keyword">try</span> {
                nalu = rtpDataBuffer.take();
            }<span class="hljs-keyword">catch</span> (Exception e)  {  }

        }
        <span class="hljs-keyword">return</span>  nalu ;
    }

    <span class="hljs-comment">/**&#x53D1;&#x9001;&#x961F;&#x5217;*/</span>
    <span class="hljs-keyword">private</span> BlockingQueue&lt;String&gt; outQueue = <span class="hljs-keyword">new</span> LinkedBlockingQueue&lt; &gt;(Integer.MAX_VALUE);;
    <span class="hljs-comment">/**
     * &#x53D1;&#x9001;&#x5B50;&#x7EBF;&#x7A0B;
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SendThread</span> <span class="hljs-keyword">extends</span>  <span class="hljs-title">Thread</span>  </span>{
        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span>  </span>{
            <span class="hljs-keyword">while</span>(!isStopReceive)  {
                <span class="hljs-keyword">try</span>  {
                    String buffer  = outQueue.poll();
                    <span class="hljs-keyword">if</span> (buffer != <span class="hljs-keyword">null</span>){
                        sendBytes(buffer);
                    }
                    <span class="hljs-comment">//&#x4F11;&#x7720;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;</span>
                    Thread.sleep(<span class="hljs-number">60</span>);
                }<span class="hljs-keyword">catch</span> (Exception e)  {}
            }
        }
    }

    <span class="hljs-comment">/**
     * &#x5F00;&#x542F;rtsp&#x5BA2;&#x6237;&#x7AEF;
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">openRtspCline</span><span class="hljs-params">()</span>  </span>{
        isStopReceive = <span class="hljs-keyword">false</span> ;
        Thread  thread = <span class="hljs-keyword">new</span> Thread(<span class="hljs-keyword">new</span> Runnable() {
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span><span class="hljs-params">()</span> </span>{
                <span class="hljs-keyword">try</span>{
                    mSocket = <span class="hljs-keyword">new</span> Socket(hostIp, port);
                    mBufferreader = <span class="hljs-keyword">new</span> BufferedReader(<span class="hljs-keyword">new</span> InputStreamReader(mSocket.getInputStream()));
                    mOutputStream = mSocket.getOutputStream();
                }<span class="hljs-keyword">catch</span> (IOException e)
                {
                    Log.i(TAG,<span class="hljs-string">&quot;&#x521B;&#x5EFA;socket&#x51FA;&#x73B0;&#x5F02;&#x5E38;=&quot;</span>+e.getLocalizedMessage()) ;
                }
            }
        });
        thread.start();

        ReceiveThread receiveThread = <span class="hljs-keyword">new</span> ReceiveThread();
        receiveThread.start();
        SendThread sendThread = <span class="hljs-keyword">new</span> SendThread() ;
        sendThread.start();

        ReceiveRTPUdpThread receiveRTPUdpThread = <span class="hljs-keyword">new</span> ReceiveRTPUdpThread();
        receiveRTPUdpThread.start();
    }

    <span class="hljs-comment">/**
     * &#x5173;&#x95ED;rtsp&#x5BA2;&#x6237;&#x7AEF;
     */</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">shutDownRtspClient</span><span class="hljs-params">()</span>  </span>{
        isStopReceive = <span class="hljs-keyword">true</span> ;
    }
}
</code></pre>
<pre><code class="lang-java"><span class="hljs-comment">/**
 *  RTP &#x6570;&#x636E;&#x5305; &#x7ED3;&#x6784;
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RtpPackage</span></span>{
    <span class="hljs-comment">/**&#x7248;&#x672C;&#x662F; 2*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> V ;
    <span class="hljs-comment">/**&#x586B;&#x5145;&#x6807;&#x5FD7;*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> P ;
    <span class="hljs-comment">/**&#x62D3;&#x5C55;&#x6807;&#x5FD7;*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> X ;
    <span class="hljs-comment">/**csrc&#x8BA1;&#x6570;&#x5668;*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> CC ;
    <span class="hljs-comment">/**&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;&#x6807;&#x8BB0;*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> M ;
    <span class="hljs-comment">/**&#x591A;&#x5A92;&#x4F53;&#x7684;&#x7C7B;&#x578B; H.264&#x7684;&#x7C7B;&#x578B;&#x4E3A;96*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> PT;
    <span class="hljs-comment">/**&#x5E8F;&#x5217;&#x53F7;*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> sequenceNumber;
    <span class="hljs-comment">/**&#x65F6;&#x95F4;&#x6233;*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">long</span> timestamp;
    <span class="hljs-comment">/**ssrc*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">long</span> ssrcIdentifier;
    <span class="hljs-comment">/**csrc&#x5217;&#x8868;*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> csrcIdentiferList ;
    <span class="hljs-comment">/**rtp &#x5305;&#x6570;&#x636E;*/</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">byte</span>[] data;
}
</code></pre>
<pre><code class="lang-java"><span class="hljs-keyword">public</span>   <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RTP2NaluTools</span></span>{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> String TAG=<span class="hljs-string">&quot;RTP2NaluTools&quot;</span> ;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> NAL_UNIT_TYPE_STAP_A = <span class="hljs-number">24</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> NAL_UNIT_TYPE_STAP_B = <span class="hljs-number">25</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> NAL_UNIT_TYPE_MTAP16 = <span class="hljs-number">26</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> NAL_UNIT_TYPE_MTAP24 = <span class="hljs-number">27</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> NAL_UNIT_TYPE_FU_A = <span class="hljs-number">28</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> NAL_UNIT_TYPE_FU_B = <span class="hljs-number">29</span>;
    <span class="hljs-comment">/**&#x4E00;&#x5E27;&#x6570;&#x636E;&#xFF08;&#x4E00;&#x4E2A;NALU&#xFF09;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">byte</span>[] NALUnit;
    <span class="hljs-comment">/**NALU&#x7ED3;&#x675F;&#x6807;&#x8BB0;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">boolean</span> NALEndFlag;
    <span class="hljs-comment">/**&#x4E34;&#x65F6;&#x53D8;&#x91CF; buffer[i] &#x5B58;&#x50A8;&#x6BCF;&#x4E00;&#x7247;&#x6570;&#x636E; */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">byte</span>[][] buffer = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[<span class="hljs-number">1024</span>][];
    <span class="hljs-comment">/**&#x5F53;&#x524D;&#x5DF2;&#x7ECF;&#x63A5;&#x6536;&#x7684;NALU&#x7684;&#x6570;&#x636E;&#x957F;&#x5EA6;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> bufferLength;
    <span class="hljs-comment">/**&#x5F53;&#x524D;&#x5DF2;&#x7ECF;&#x63A5;&#x6536;&#x7684;&#x6570;&#x636E;&#x7247;&#x6570;&#x91CF;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> packetNum;
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">RTP2NaluTools</span><span class="hljs-params">()</span>  </span>{
        NALEndFlag = <span class="hljs-keyword">false</span>;
        bufferLength= <span class="hljs-number">0</span>;
        packetNum =<span class="hljs-number">0</span>;
    }

    <span class="hljs-comment">/**
     * &#x5C06; rtp&#x5305; &#x7EC4;&#x6210; NALU &#x683C;&#x5F0F;&#x7684;&#x6570;&#x636E; &lt;br&gt;
     *     &#x8FD4;&#x56DE;&#x4E00;&#x5E27;H264&#x6570;&#x636E;(&#x4E00;&#x4E2A;NALU)
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">byte</span>[] rtpPackage2NALU(<span class="hljs-keyword">byte</span>[] rtpData)  {
        <span class="hljs-keyword">if</span>(rtpData.length == <span class="hljs-number">0</span>)  {
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span> ;
        }
        RtpPackage rtpPackage = <span class="hljs-keyword">new</span> RtpPackage();
        rtpPackage.V=(rtpData[<span class="hljs-number">0</span>]&amp;<span class="hljs-number">0xFF</span>)&gt;&gt;<span class="hljs-number">6</span> ;
        rtpPackage.PT = rtpData[<span class="hljs-number">1</span>] &amp; <span class="hljs-number">0x7F</span>;
        rtpPackage.data = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[rtpData.length-<span class="hljs-number">12</span>];
        System.arraycopy(rtpData, <span class="hljs-number">12</span>, rtpPackage.data, <span class="hljs-number">0</span>, rtpData.length - <span class="hljs-number">12</span>);
        <span class="hljs-keyword">if</span>( (rtpPackage.V != <span class="hljs-number">2</span>)&amp;&amp;(rtpPackage.PT!=<span class="hljs-number">96</span>) || rtpPackage.data.length &lt;<span class="hljs-number">2</span> )  {
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
        }
        <span class="hljs-comment">// rtp&#x5C01;&#x5305;&#x65B9;&#x5F0F;&#xFF0C;&#x5355;&#x4E00;&#x5C01;&#x5305;&#x3001;&#x7EC4;&#x5408;&#x5C01;&#x5305;&#x3001;&#x5206;&#x7247;&#x5C01;&#x5305;&#x7B49; 0x1F -&gt; 0001 1111</span>
        <span class="hljs-keyword">int</span> fuIndicatorTypeFlag = rtpPackage.data[<span class="hljs-number">0</span>] &amp; <span class="hljs-number">0x1F</span>;
        <span class="hljs-comment">// FU head&#x4E2D;&#x7684; S&#x3001;E&#x6807;&#x8BB0; &#x7528;&#x6765;&#x5224;&#x65AD;NALU&#x7684;&#x5F00;&#x59CB;&#x3001;&#x7ED3;&#x675F; 0xCO -&gt;  1100 0000  &#x53D6;S&#x3001;E</span>
        <span class="hljs-keyword">int</span> fuHeadSEFlag = rtpPackage.data[<span class="hljs-number">1</span>] &amp; <span class="hljs-number">0xC0</span>;

        <span class="hljs-keyword">switch</span> (fuIndicatorTypeFlag)  {
            <span class="hljs-keyword">case</span> NAL_UNIT_TYPE_STAP_A:
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> NAL_UNIT_TYPE_STAP_B:
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> NAL_UNIT_TYPE_MTAP16:
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> NAL_UNIT_TYPE_MTAP24:
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> NAL_UNIT_TYPE_FU_B:
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> NAL_UNIT_TYPE_FU_A:
                <span class="hljs-keyword">switch</span> (fuHeadSEFlag)  {
                    <span class="hljs-comment">//NAL Unit start packet 0x80-&gt; 1000 0000</span>
                    <span class="hljs-keyword">case</span> <span class="hljs-number">0x80</span>:
                        NALEndFlag = <span class="hljs-keyword">false</span>;
                        bufferLength = rtpPackage.data.length-<span class="hljs-number">1</span> ;
                        buffer[<span class="hljs-number">0</span>] = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[rtpPackage.data.length-<span class="hljs-number">1</span>];
                        <span class="hljs-comment">/*
                        &#x6BCF;&#x4E00;&#x5E27;&#x5F00;&#x59CB;&#x7684;&#x65F6;&#x5019;&#x8981;&#x52A0;&#x4E0A;&#x8868;&#x793A;&#x8FD9;&#x4E2A;&#x5E27;&#x7C7B;&#x578B;&#x7684;&#x4FE1;&#x606F;&#x3002;
                        0xE0 -&gt;1110 0000    0x1F -&gt; 0001 1111
                        &#x53D6;FU indicator&#x7684;&#x524D;&#x4E09;&#x4F4D;&#x548C;FU Header&#x7684;&#x540E;&#x4E94;&#x4F4D;&#x3002;
                        &#x6700;&#x540E;&#x8FD9;&#x4E2A;byte&#x5305;&#x542B;&#x4E86;  F &#x3001;NRI &#x3001;Type &#x8FD9;&#x4E09;&#x4E2A;&#x4FE1;&#x606F;
                        F&#x53EF;&#x4EE5;&#x5FFD;&#x7565;&#xFF0C; NRI&#x6807;&#x8BB0;&#x8FD9;&#x4E2A;NALU&#x7684;&#x91CD;&#x8981;&#x6027; &#xFF0C;Type&#x6807;&#x8BB0;&#x5E27;&#x7C7B;&#x578B;
                        buffer[0][0] &#x5E27;&#x7C7B;&#x578B;&#x6570;&#x636E; 41&#x3001;61&#x3001;65&#x3001;67&#x3001;68&#x7B49;
                         */</span>
                        buffer[<span class="hljs-number">0</span>][<span class="hljs-number">0</span>] = (<span class="hljs-keyword">byte</span>)((rtpPackage.data[<span class="hljs-number">0</span>] &amp; <span class="hljs-number">0xE0</span>)|(rtpPackage.data[<span class="hljs-number">1</span>]&amp;<span class="hljs-number">0x1F</span>));
                        System.arraycopy(rtpPackage.data,<span class="hljs-number">2</span>,buffer[<span class="hljs-number">0</span>],<span class="hljs-number">1</span>,rtpPackage.data.length-<span class="hljs-number">2</span>);
                        packetNum = <span class="hljs-number">1</span>;
                        <span class="hljs-keyword">break</span>;
                    <span class="hljs-comment">//NAL Unit middle packet   0x00-&gt;0000 0000</span>
                    <span class="hljs-keyword">case</span> <span class="hljs-number">0x00</span>:
                        NALEndFlag = <span class="hljs-keyword">false</span>;
                        bufferLength += rtpPackage.data.length-<span class="hljs-number">2</span>;
                        buffer[packetNum] = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[rtpPackage.data.length-<span class="hljs-number">2</span>];
                        System.arraycopy(rtpPackage.data,<span class="hljs-number">2</span>,buffer[packetNum],<span class="hljs-number">0</span>,rtpPackage.data.length-<span class="hljs-number">2</span>);
                        packetNum++;
                        <span class="hljs-keyword">break</span>;
                    <span class="hljs-comment">//NAL Unit end packet  0x40 --&gt;0100 0000</span>
                    <span class="hljs-keyword">case</span> <span class="hljs-number">0x40</span>:
                        NALEndFlag = <span class="hljs-keyword">true</span>;
                        <span class="hljs-comment">//+4 &#x662F;&#x56E0;&#x4E3A;&#x591A;&#x4E86; 00 00 00 01</span>
                        NALUnit = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[bufferLength + rtpPackage.data.length- <span class="hljs-number">2</span> + <span class="hljs-number">4</span>];
                        <span class="hljs-comment">//&#x56E0;&#x4E3A;&#x6253;&#x5305;&#x53D1;&#x9001;&#x7684;&#x65F6;&#x5019;&#x662F;&#x53BB;&#x6389;&#x4E86;00 01&#x8FD9;&#x79CD;&#x6807;&#x8BB0;&#x4F4D;&#x7684;&#xFF0C;&#x4E3A;&#x4E86;&#x5904;&#x7406;&#x540E;&#x7EED;&#x7684;H264&#xFF0C;&#x9700;&#x8981;&#x624B;&#x52A8;&#x52A0;&#x4E0A;</span>
                        NALUnit[<span class="hljs-number">0</span>] = <span class="hljs-number">0x00</span>;
                        NALUnit[<span class="hljs-number">1</span>] = <span class="hljs-number">0x00</span>;
                        NALUnit[<span class="hljs-number">2</span>] = <span class="hljs-number">0x00</span>;
                        NALUnit[<span class="hljs-number">3</span>] = <span class="hljs-number">0x01</span>;
                        <span class="hljs-keyword">int</span> tmpLen = <span class="hljs-number">4</span>;
                        <span class="hljs-comment">//&#x7B2C;&#x4E00;&#x7247; + &#x4E2D;&#x95F4;&#x7247; &#x6570;&#x636E;</span>
                        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; packetNum; ++i)
                        {
                            System.arraycopy(buffer[i],<span class="hljs-number">0</span>,NALUnit,tmpLen,buffer[i].length);
                            tmpLen += buffer[i].length;
                        }
                        <span class="hljs-comment">//&#x6700;&#x540E;&#x4E00;&#x7247;&#x7684;&#x6570;&#x636E;</span>
                        System.arraycopy(rtpPackage.data,<span class="hljs-number">2</span>,NALUnit,tmpLen,rtpPackage.data.length-<span class="hljs-number">2</span>);
                        <span class="hljs-keyword">break</span>;
                }
                <span class="hljs-keyword">break</span>;

            <span class="hljs-comment">//&#x8FD9;&#x91CC;&#x91C7;&#x7528;&#x6392;&#x9664;&#x6CD5;&#xFF0C;&#x6392;&#x9664;&#x4E86;&#x7EC4;&#x5305;&#x5C01;&#x88C5;&#x548C;&#x5206;&#x7247;&#x5C01;&#x88C5; &#x4E4B;&#x540E;&#x5C31;&#x8BA4;&#x4E3A;&#x662F; &#x5355;&#x4E2A;&#x6253;&#x5305;&#x6A21;&#x5F0F;</span>
            <span class="hljs-keyword">default</span>:
                NALUnit = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[<span class="hljs-number">4</span>+rtpPackage.data.length];
                NALUnit[<span class="hljs-number">0</span>] = <span class="hljs-number">0x00</span>;
                NALUnit[<span class="hljs-number">1</span>] = <span class="hljs-number">0x00</span>;
                NALUnit[<span class="hljs-number">2</span>] = <span class="hljs-number">0x00</span>;
                NALUnit[<span class="hljs-number">3</span>] = <span class="hljs-number">0x01</span>;
                System.arraycopy(rtpPackage.data,<span class="hljs-number">0</span>,NALUnit,<span class="hljs-number">4</span>,rtpPackage.data.length);
                NALEndFlag = <span class="hljs-keyword">true</span>;
                <span class="hljs-keyword">break</span>;
        }
        <span class="hljs-keyword">if</span>(NALEndFlag)  {
           <span class="hljs-keyword">return</span>  NALUnit;
        }<span class="hljs-keyword">else</span>{
            <span class="hljs-keyword">return</span>  <span class="hljs-keyword">null</span>;
        }
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">stop</span><span class="hljs-params">()</span>  </span>{
        NALUnit = <span class="hljs-keyword">null</span>;
    }
}
</code></pre>
<h3 id="&#x4F7F;&#x7528;&#x65B9;&#x6CD5;"><a name="&#x4F7F;&#x7528;&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x4F7F;&#x7528;&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4.1. &#x4F7F;&#x7528;&#x65B9;&#x6CD5;</h3>
<pre><code class="lang-java"><span class="hljs-keyword">boolean</span> isTCPtranslate = <span class="hljs-keyword">false</span> ; <span class="hljs-comment">//false  true</span>
String hostIp =<span class="hljs-string">&quot;192.168.1.235&quot;</span>;
<span class="hljs-keyword">int</span> port= <span class="hljs-number">554</span> ;
String rtspUrl =<span class="hljs-string">&quot;rtsp://192.168.1.235:554/&quot;</span>;
String authorName=<span class="hljs-keyword">null</span> ;
String authorPassword=<span class="hljs-keyword">null</span> ;
RtspClient rtspClient = <span class="hljs-keyword">new</span> RtspClient( isTCPtranslate,  hostIp, port,  rtspUrl , authorName, authorPassword);
rtspClient.openRtspCline();

<span class="hljs-comment">//&#x8BF7;&#x6C42;options</span>
rtspClient.doOption();
<span class="hljs-comment">//&#x8BF7;&#x6C42;describe</span>
rtspClient.doDescribe();
<span class="hljs-comment">//&#x8BF7;&#x6C42;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;(&#x6B64;&#x9636;&#x6BB5;&#x6307;&#x660E;&#x7528;Tcp&#x6216;UDP&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;)</span>
rtspClient.doSetup();
<span class="hljs-comment">//&#x8BF7;&#x6C42;&#x5F00;&#x59CB;&#x4E0B;&#x53D1;Rtp&#x5305;</span>
rtspClient.doPlay();

<span class="hljs-comment">//&#x5F00;&#x542F;&#x5B50;&#x7EBF;&#x7A0B;&#x63A5;&#x6536;RTP&#x6570;&#x636E;</span>
 <span class="hljs-keyword">byte</span>[] rtpData =rtspClient.getRtpData() ;
<span class="hljs-comment">//&#x5BF9;Rtp&#x6570;&#x636E;&#x8FDB;&#x884C;&#x89E3;&#x6790;&#xFF0C;&#x83B7;&#x5F97;H264&#x6570;&#x636E;</span>
<span class="hljs-keyword">byte</span>[] nalu= rtp2NaluTools.rtpPackage2NALU(rtpData) ;
</code></pre>
<footer class="page-footer"><span class="copyright">&#x65E0;&#x7248;&#x6743; &#x53EF;&#x4EE5;&#x65E0;&#x9650;&#x5236;&#x4F7F;&#x7528;&#xFF01; all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2020-08-20 14:17:31
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="音视频基础.html" class="navigation navigation-prev " aria-label="Previous page: 音视频基础">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="RTP.html" class="navigation navigation-next " aria-label="Next page: RTP">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"RTSP","level":"1.13.2","depth":2,"next":{"title":"RTP","level":"1.13.3","depth":2,"path":"chinese/视频相关/RTP.md","ref":"chinese/视频相关/RTP.md","articles":[]},"previous":{"title":"音视频基础","level":"1.13.1","depth":2,"path":"chinese/视频相关/音视频基础.md","ref":"chinese/视频相关/音视频基础.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","versions-select","fontsettings","sharing","tbfed-pagefooter","donate","local-video","splitter","edit-link","expandable-chapters","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"无版权 可以无限制使用！","modify_label":"该文件更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"versions-select":{"type":"branches"},"donate":{"alipay":"https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201803011956_osChina_支付宝收款码.png","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201803011956_osChina_微信收款码.png","wechatText":"微信打赏"},"fontsettings":{"family":"sans","size":2,"theme":"sepia"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"versions":{"options":[{"value":"https://www.aivin666.cn/java_android/","text":"v1.0"}]},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":false,"google":true,"instapaper":false,"twitter":false,"vk":false,"weibo":true},"edit-link":{"label":"托管页面","base":"https://www.baidu.com/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/视频相关/RTSP.md","mtime":"2020-08-20T06:17:31.534Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-20T09:02:41.305Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-versions-select/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

